home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.kei.com!wang!news
- From: emild@cs.technion.ac.il (Kohn Emil Dan)
- Subject: Re: EMM386 Problem - main.c (0/1)
- Organization: Technion, Israel Institute of Technology
- Date: Thu, 4 Jan 1996 12:00:16 GMT
- Message-ID: <Pine.SV4.3.91-heb-2.04.960104122025.16292B-100000@cs.technion.ac.il>
- Sender: news@wang.com
-
-
-
- On Wed, 3 Jan 1996, Paul Anderson wrote:
-
- > "Ian G. Crozier" <ian_g_crozier@cngp.cng.com> wrote:
- >
- > >panderso@ebtech.net (Paul Anderson) wrote:
- > >>I'm writing a menu program, I don't have much of it done yet, but on
- > >>running the exec of what I have done I get EMM386 Exception error #12
- > >>or #06. I use Watcom's compiler. I've attached the source.
- > >>
- >
- > >I'm not surprised that you're having problems with your program.
- >
- > >You've posted NINE messages, none of which give any useful information
- > >about your code!!
- >
- > Uh-ohhhh....... Sorry, mail reader hickup... Some of them where
- > supposed to have the source attached, but, I can't change the
- > encoding!!! I can just import the source, and here goes:
- >
- > /*
- > A menu prog, I am bored, so, why not put in *MY* bid to take
- > the place of MM? Oooohhhh.... Let's see,
- > We want lots of configurability. Igor! Bring the config
- > files!
- > */
- >
- > #include <stdio.h>
- > #include <stdlib.h>
-
- #include <string.h>
- ^-------------if you want to follow my advice, then you'll
- have to include this, too
-
- > #include "menu.h"
- >
- > main(int argc, char *argv[])
- > {
- > int i=1;
-
- > /* Engage command-line parser! */
- >
- > if (argc == 1) {
- > printf("\a\nUuuuhhhhh... Yer supposed to tell me the
- > config file name.");
- > exit(0);
- > }
- > /* Okey-dokey, got that down, let's plop up the for loop.*/
- > while(0==0) /* Index=2(i.e. second param, first is: menu.exe)
- > Up Mr. Index. */
- > {
- > /* printf("%s", argv[i]);*/
- > /* Bug test... */
- > /*i=i + 1;*/
- > /* We only need the config file name, nothing else. */
- > /* Remember, include config file var def in h file. */
- > config=fopen(argv[i], "r" );
- > if (config == NULL)
- > {
- > /* Uh-oh... *BIG* problem... */
- > printf("\a\nError: Unable to open config file
- > %s!", argv[i]);
- > printf("\nRead docs for help.");
- > exit(1);
- > }
- > /* Now, let us test the error. */
- >
- > i=loadcnf(config);
- > exit(0); /* Exit prog...*/
- >
- > }
- > /*Let's roast this sucker....*/
- > }
- >
- > atexit()
- > {
- > fclose(config);
- > return 0;
- > }
- >
- > /* Config file data loader. */
- >
- > int loadcnf(FILE *in)
- > {
- > char indata[40];
- > int tmp;
- > /* Struct defed in menu.h... */
- > fscanf(in,"%s", &indata);
- > if (indata=="ON")
- ^-----------Here you are comparing the address of the
- first element of indata to the address
- of "O" in "ON". I don't think they will
- ever be equal
-
- You should use
- if (strcmp(indata,"ON")==0)
- instead of your if statement
- > {
- > tmp=1;
- > }
- > else
- > {
- > tmp=0;
- > }
- > /*Parms.Color = tmp;*/
- > /*indata="";*/
- > fscanf(in, "%s", &indata);
- ^------Don't use the & here: indata as a
- parameter to fscanf is a pointer to its
- first element (a char*, exactly what you need
- This applies to all your usages of fscanf
- ^----Data is read in indata
- > Parms.EntryOne = indata; /* The beginnings of a long and
- painful process...*/
- ^-----EntryOne points to the first character of
- indata
- > /*indata="";*/
- > fscanf(in, "%s", &indata);
- ^-----new data is read into indata
- Now Params.EntryOne will point to the new
- value that is stored in indata
- > Parms.EntryOnePath = indata;
- ^------Params.EntryOnePath points to the same
- place, wherer Params.EntryOne Points
- .
- .
- .
-
-
- After your assignments, all the Params fields will point to the same place:
- the last value read by fscanf in indata. I don't think this is what you
- wanted.
-
-
- In order to corrrect the problem, replace the assignmnents like this:
-
- Instead of
- Params.EntryOne=indata;
-
- use:
-
- if((Params.EntryOne=malloc(strlen(indata)+1))==NULL)
- {
- fprintf(stderr,"Not enough memory\n");
- exit(1);
- }
- strcpy(Parrams.EntryOne,indata);
-
-
-
- OR
-
- redeclare the fields in the Parms struct to be char[40] instead of
- char*, and instead of
-
- Params.EntryOne=indata;
-
- use
-
- strcpy(Params.Entryone,indata);
-
-
-
-
- > /* YESSSSSSS!!!!! I am *DONE* setting up the config
- > reader!!!*/
- > return 0;
- > }
- > And the header file:
- >
- > /* Filling garbage...*/
- > FILE *config;
- > struct
- > {
- > int *Color;
- > char *EntryOne;
- > char *EntryOnePath;
- > char *EntryTwo;
- > char *EntryTwoPath;
- > char *EntryThree;
- > char *EntryThreePath;
- > char *EntryFour;
- > char *EntryFourPath;
- > char *EntryFive;
- > char *EntryFivePath;
- > char *EntrySix;
- > char *EntrySixPath;
- > char *RegName;
- > } Parms;
- >
- > int loadcnf(FILE *in);
- >
- > /*Parms data;*/
- >
- > Sorry for the mistake!!! TTYL!
- >
- >
-
- Hope that this helps.
-
-
- Best regards,
-
- Emil
-